HAL GPIO types migration

This section provides information about the HAL GPIO types migration .

HAL GPIO initialization type definition

In HAL2, Pin selection is removed from the configuration structure, GPIO mode and output type are defined separately using distinct enumerations hal_gpio_mode_t and hal_gpio_output_t and init_state is added to the the config structure.

HAL1

HAL2

typedef struct
{
  uint32_t Pin;
  uint32_t Mode;
  uint32_t Pull;
  uint32_t Speed;

  uint32_t Alternate;

} GPIO_InitTypeDef;
typedef struct
{

  hal_gpio_mode_t       mode;
  hal_gpio_pull_t       pull;
  hal_gpio_speed_freq_t speed;
  hal_gpio_output_t     output_type;
  hal_gpio_af_t         alternate;
  hal_gpio_pin_state_t  init_state;
} hal_gpio_config_t;

Related concepts:


HAL GPIO pin set and pin reset type definition

HAL1

HAL2

typedef enum
{
  GPIO_PIN_RESET,
  GPIO_PIN_SET
} GPIO_PinState;
typedef enum
{
  HAL_GPIO_PIN_RESET,
  HAL_GPIO_PIN_SET
} hal_gpio_pin_state_t;

Related concept: Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

LPGPIO mapping structure definition type

HAL1

HAL2

typedef struct
{
  GPIO_TypeDef *GPIO_PORT;
  uint32_t Pin_Pos;
} LPGPIO_MapTypeDef;

In HAL2, the LPGPIO mapping structure are now identified using the hal_gpio_t enumeration, and the pins are specified using HAL_GPIO_PIN_x constants.